package com.zhaoxi.project.wms.controller;

import com.zhaoxi.framework.aspectj.lang.annotation.Log;
import com.zhaoxi.framework.aspectj.lang.enums.BusinessType;
import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.project.wms.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 产品Controller
 *
 * @author zhaoxi
 * @date 2023-07-22
 */
@RestController
@RequestMapping("/wms/product")
public class ProductController extends BaseService {
  @Autowired
  private ProductService productService;

  //  获列表
  @PreAuthorize("@ss.hasPermi('wms:product:list')")
  @GetMapping("/getList")
  public PageData getList(Map map) {
    PageData pd = this.getPageData(map);
    //如果 pageNum 和 pageSize 都是有值的，就是需要分页的
    if (pd.getLong("pageNum") != null && pd.getLong("pageSize") != null) {
      this.startPage();
    }
    return this.responses(productService.getList(pd));
  }


  //  新增
  @PreAuthorize("@ss.hasPermi('wms:product:add')")
  @Log(title = "产品管理", businessType = BusinessType.INSERT)
  @PostMapping
  public PageData add(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return productService.add(pd);
  }

  //  修改
  @PreAuthorize("@ss.hasPermi('wms:product:edit')")
  @Log(title = "产品管理", businessType = BusinessType.UPDATE)
  @PutMapping
  public PageData edit(@RequestBody Map map) {
    PageData pd = this.getPageData(map);
    return productService.edit(pd);
  }

  //  删除
  @PreAuthorize("@ss.hasPermi('wms:product:del')")
  @Log(title = "产品管理", businessType = BusinessType.DELETE)
  @DeleteMapping("id/{id}")
  public PageData del(@PathVariable Long id) {
    return productService.del(id);
  }



  //  获详细
  @PreAuthorize("@ss.hasPermi('wms:product:picture')")
  @GetMapping("/getPictureList")
  public PageData getPictureList(Map map) {
    PageData pd = this.getPageData(map);
    return this.success(productService.getPictureList(pd));
  }
}
